package com.bkgy.controller.driver;

import com.bkgy.controller.repTechFit.service.IRepTechFitService;
import com.bkgy.controller.technology.service.*;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.DateUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Tag(name = "基础数据构建")
@Controller
@RequestMapping("/driver")
@RequiredArgsConstructor
public class TechFitController {
    private final ITechParamService duxinParamService;
    private final ITechTcmParamService tcmParamService;
    private final ITechAnnealingParamService annealingParamService;
    private final ITcm2280ProcessService tcmService;
    private final ICalProcessService calService;
    private final ICgl1870ProcessService cglService;
    private final IRepTechFitService repTechFitService;

    @Operation(summary = "酸轧每日合格率汇总，表：REP_TECH_FIT", description = "每日按班组统计入口段、酸洗段、轧制段合格率")
    @PostMapping("/REP_TECH_FIT/buildSucRate")
    @ResponseBody
    public ResultData<String> buildSucRate(String startDay, String endDay) {
        Date d1 = DateUtil.getStringToDate("yyyyMMdd", startDay);
        Date d2 = DateUtil.getStringToDate("yyyyMMdd", endDay);

        while (d1.before(d2)) {
            repTechFitService.buildSucRateJob(d1);
            d1 = DateUtil.getAfterDate(d1);
        }
        return ResultData.ResultDataSuccess("success");
    }

    @Operation(summary = "导入镀锌工艺参数", description = "T_TECH_PARAM")
    @PostMapping("/REP_TECH_FIT/importTechParam")
    @ResponseBody
    public ResultData<String> importTechParam() {
        return duxinParamService.importTechParam();
    }

    @Operation(summary = "导入连退工艺参数", description = "T_TECH_ANNEALING_PARAM")
    @PostMapping("/T_TECH_ANNEALING_PARAM/importTechAnnealingParam")
    @ResponseBody
    public ResultData<String> importTechAnnealingParam() {
        return annealingParamService.importTechParam();
    }

    @Operation(summary = "导入酸轧工艺参数", description = "T_TECH_TCM2280_PARAM")
    @PostMapping("/T_TECH_TCM2280_PARAM/importTechTcm2280Param")
    @ResponseBody
    public ResultData<String> importTechTcm2280Param() {
        return tcmParamService.importTechParam();
    }

    @Operation(summary = "镀锌工艺参数符合率/验证符合度", description = "验证镀锌符合度测试 yyyy-MM-dd")
    @PostMapping("/CGL1870_PROCESS_DATAS/checkTechParam")
    @ResponseBody
    public ResultData<String> checkTechParam(String beginTime) {
        return cglService.transData(beginTime.replaceAll("-", ""));
    }

    @Operation(summary = "连退工艺参数符合率/验证符合度", description = "验证连退符合度yyyyMMddHHmmss")
    @PostMapping("/CAL_PROCESS_DATAS/checkTechAnnealingParam")
    @ResponseBody
    public ResultData<String> checkTechAnnealingParam(String beginTime) {
        return calService.transData(beginTime);
    }

    @Operation(summary = "验证酸轧符合度 TCM2280_PROCESS_DATAS", description = "验证酸轧符合度")
    @PostMapping("/TCM2280_PROCESS_DATAS/checkTechTcmParam")
    @ResponseBody
    public ResultData<String> checkTechTcmParam(String beginDate, String endDate) {
        String begin = beginDate.replaceAll("-", "");
        String end = endDate.replaceAll("-", "");
        return tcmService.transData(begin, end);
    }
}
